/*
 * Copyright © 2021 http://www.hn-szzy.com/ All rights reserved.
 */
package com.xjh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ejlchina.searcher.BeanSearcher;
import com.ejlchina.searcher.operator.Equal;
import com.ejlchina.searcher.param.Operator;
import com.ejlchina.searcher.util.MapUtils;
import com.xjh.bo.AclUserBO;
import com.xjh.bo.BeanSearchStudentBO;
import com.xjh.mapper.AclUserMapper;
import com.xjh.po.AclUserPO;
import com.xjh.service.AclUserService;
import com.xjh.utils.beanutils.BeanCopyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author： 徐建华
 * @date： 2022/2/13
 * @description：
 */
@Service
public class AclUserServiceImpl extends ServiceImpl<AclUserMapper, AclUserPO> implements AclUserService {
    @Autowired
    private AclUserMapper aclUserMapper;

    @Autowired
    private BeanSearcher beanSearcher;

    @Override
    public List<AclUserBO> queryAll() {

        QueryWrapper<AclUserPO> wrapper = new QueryWrapper<>();
        List<AclUserPO> aclUserPOS = aclUserMapper.selectList(wrapper);
        List<AclUserBO> userList = BeanCopyUtils.copyList(aclUserPOS, AclUserBO.class);
        return userList;
    }

    @Override
    public List<BeanSearchStudentBO> testBeanSearcher() {
        /**
         * field：字段名 和 字段值
         * op:字段运算符，不写默认是equal
         * ic:
         *
         *
         */

        /**1.测试单表条件查询*/
        String name = null;
        Map<String, Object> params = MapUtils.builder()
                // 以 建华 (忽略大小写) 开头
                .field(BeanSearchStudentBO::getStuName, "建华").op(Operator.StartWith).ic()
                .field(BeanSearchStudentBO::getStuName, name).op(Operator.StartWith).ic()
                .field(BeanSearchStudentBO::getStuName, "建华1").op(Operator.StartWith).ic()
                .orderBy(BeanSearchStudentBO::getId, "asc")
                .page(0, 10)
                .build();
        List<BeanSearchStudentBO> students = beanSearcher.searchList(BeanSearchStudentBO.class, params);
        return students;
    }
}
